package com.shengwei.truck.driver.view.adapter.mine;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;
import com.shengwei.truck.driver.R;
import com.shengwei.truck.driver.bean.JsonCar;
import com.shengwei.truck.driver.databinding.CarModelListItemBinding;
import java.util.List;

/**
 * 显示车辆型号列表的 适配器
 */
public class CarModelAdapter extends RecyclerView.Adapter<CarModelAdapter.ViewHolder> {
    private List<JsonCar> mNames;
    private Context mContext;

    private LayoutInflater mInflater;
    public CarModelAdapter(List<JsonCar> names, Context context) {
        mInflater = LayoutInflater.from(context);
        mNames = names;
        mContext = context;
    }
    public void notifyDataSetChanged(List<JsonCar> dataList) {
        this.mNames = dataList;
        super.notifyDataSetChanged();
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        CarModelListItemBinding carModelItemBinding = DataBindingUtil.inflate(mInflater, R.layout.car_model_list_item,parent,false);
        return new CarModelAdapter.ViewHolder(carModelItemBinding);
    }
    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        CarModelListItemBinding JsonCarModelItemBinding = (CarModelListItemBinding) holder.viewDataBinding;
        JsonCar JsonCar = mNames.get(position);
        JsonCarModelItemBinding.setCarName(JsonCar.name);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return mNames.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ViewDataBinding viewDataBinding;
        public ViewHolder(ViewDataBinding viewDataBinding) {
            super(viewDataBinding.getRoot());
            this.viewDataBinding = viewDataBinding;
        }
    }
}
